package day17_Inet.demo10_TCP;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class Clien_TCP {
    public static void main(String[] args) throws Exception{
        Socket socket = new Socket("127.0.0.1", 8888);
        while (true){
            //发送
            OutputStream os = socket.getOutputStream();
            os.write("abcdefg".getBytes());
//           socket.shutdownOutput();//禁用outputStream流
            //shutdownOutput可以解决阻塞,但是循环不能用
            os.flush();
            //接收
            InputStream is = socket.getInputStream();
            byte[] bytes = new byte[1024];
            int i = is.read(bytes);
            String s = new String(bytes, 0, i);
            if(s.equals("bye")){
                break;
            }
        }
        socket.close();

    }
}
